package com.xiaoKe.zhonghzu.global.base;

import android.content.Context;
import android.content.Intent;

import androidx.fragment.app.Fragment;

import com.xiaoKe.zhonghzu.global.tool.ResourceTool;


public class AppRouter {
    public static void toFragment(Context context, RouterConfig routerConfig) {
        Intent intent = new Intent(context, FragmentContainerActivity.class);
        intent.putExtra("className", routerConfig.getClassReference());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.putExtra("title", routerConfig.getTitle());
        intent.putExtra("type", 1);
        if (routerConfig.getBundleExtra() != null) {
            intent.putExtras(routerConfig.getBundleExtra());
        }
        context.startActivity(intent);
    }

    public static void toFragmentForResult(Fragment fragment, RouterConfig routerConfig, int requestCode) {
        Intent intent = new Intent(fragment.getContext(), FragmentContainerActivity.class);
        intent.putExtra("className", routerConfig.getClassReference());
        intent.putExtra("title", routerConfig.getTitle()); 
        if (routerConfig.getBundleExtra() != null) {
            intent.putExtras(routerConfig.getBundleExtra());
        }
        fragment.startActivityForResult(intent, requestCode);
    }

    public static void toFragmentForResult(BaseActivity baseActivity, RouterConfig routerConfig, int requestCode) {
        Intent intent = new Intent(baseActivity, FragmentContainerActivity.class);
        intent.putExtra("className", routerConfig.getClassReference());
        intent.putExtra("title", routerConfig.getTitle());
        if (routerConfig.getBundleExtra() != null) {
            intent.putExtras(routerConfig.getBundleExtra());
        }
        baseActivity.startActivityForResult(intent, requestCode);

    }

}

